/**
 * 详情对话框
 */
var BasicCarrierInfoDlg = {
    data: {
        operateId: "",
        operateName: "",
        carrierNumber: "",
        carrierName: "",
        types: "",
        abbreviation: "",
        city: "",
        xukezheng: "",
        business: "",
        legal: "",
        contacts: "",
        tel: "",
        xukezhengfazhengriqi: "",
        xukezhengqishiriqi: "",
        xukezhengzhongzhiriqi: "",
        xukezhengfazhengjiguan: "",
        credit: "",
        address: "",
        bank: "",
        bankAddress: "",
        bankAccount: "",
        taxRate: "",
        notes: "",
        farenzhaopianfileid: "",
        xukezhengfileid: "",
        yinhangkafileid: "",
        createTime: "",
        updateTime: "",
        createUser: "",
        updateUser: "",
        deptId: "",
        deliverId: "",
        v1: "",
        v2: ""
    }
};

layui.use(['form', 'admin', 'ax', 'laydate', 'upload'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var laydate = layui.laydate;
    var upload = layui.upload;

    //让当前iframe弹层高度适应
    admin.iframeAuto();

    // 渲染时间选择框
    laydate.render({
        elem: '#xukezhengfazhengriqi'
    });

    // 渲染时间选择框
    laydate.render({
        elem: '#xukezhengqishiriqi'
    });

    // 渲染时间选择框
    laydate.render({
        elem: '#xukezhengzhongzhiriqi'
    });

    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/basicCarrier/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    form.val('basicCarrierForm', result.data);
    if(result.data.farenzhaopianfileid != null && result.data.farenzhaopianfileid != ""){
        $('#avatarPreview').attr('src', '/system/previewa/' + result.data.farenzhaopianfileid);
    }
    if(result.data.xukezhengfileid != null && result.data.xukezhengfileid != ""){
        $('#avatarPreview2').attr('src', '/system/previewa/' + result.data.xukezhengfileid);
    }
    if(result.data.yinhangkafileid != null && result.data.yinhangkafileid != ""){
        $('#avatarPreview3').attr('src', '/system/previewa/' + result.data.yinhangkafileid);
    }

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/basicCarrier/editItem", function (data) {
            Feng.success("Update successful!");
            window.location.href = Feng.ctxPath + '/basicCarrier'
        }, function (data) {
            Feng.error("Update failed!" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });
    
    upload.render({
        elem: '#imgHead'
        , url: Feng.ctxPath + '/system/upload'
        , before: function (obj) {
            obj.preview(function (index, file, result) {
                $('#avatarPreview').attr('src', result);
            });
        }
        , done: function (res) {
            $('#farenzhaopianfileid').val(res.data.fileId);
        }
        , error: function () {
            Feng.error("Upload failed!");
        }
    });

    //返回按钮
    $("#backupPage").click(function () {
        window.location.href = Feng.ctxPath + '/basicCarrier'
    });

});

layui.use(['ax', 'upload'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var upload = layui.upload;
    
    upload.render({
        elem: '#imgHead2'
        , url: Feng.ctxPath + '/system/upload'
        , before: function (obj) {
            obj.preview(function (index, file, result) {
                $('#avatarPreview2').attr('src', result);
            });
        }
        , done: function (res) {
            $('#xukezhengfileid').val(res.data.fileId);
        }
        , error: function () {
            Feng.error("Upload failed!");
        }
    });
});

layui.use(['ax', 'upload'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var upload = layui.upload;
    
    upload.render({
        elem: '#imgHead3'
        , url: Feng.ctxPath + '/system/upload'
        , before: function (obj) {
            obj.preview(function (index, file, result) {
                $('#avatarPreview3').attr('src', result);
            });
        }
        , done: function (res) {
            $('#yinhangkafileid').val(res.data.fileId);
        }
        , error: function () {
            Feng.error("Upload failed!");
        }
    });
});